Problem: A triangle has side lengths 7, 8, and 9.  There are exactly two lines that simultaneously bisect the perimeter and area of the triangle.  Let $\theta$ be the acute angle between these two lines.  Find $\tan \theta.$

[asy]
unitsize(0.5 cm);

pair A, B, C, P, Q, R, S, X;

B = (0,0);
C = (8,0);
A = intersectionpoint(arc(B,7,0,180),arc(C,9,0,180));
P = interp(A,B,(12 - 3*sqrt(2))/2/7);
Q = interp(A,C,(12 + 3*sqrt(2))/2/9);
R = interp(C,A,6/9);
S = interp(C,B,6/8);
X = extension(P,Q,R,S);

draw(A--B--C--cycle);
draw(interp(P,Q,-0.2)--interp(P,Q,1.2),red);
draw(interp(R,S,-0.2)--interp(R,S,1.2),blue);

label("$\theta$", X + (0.8,0.4));
[/asy]
Solution: Let the triangle be $ABC,$ where $AB = 7,$ $BC = 8,$ and $AC = 9.$  Let the two lines be $PQ$ and $RS,$ as shown below.

[asy]
unitsize(0.6 cm);

pair A, B, C, P, Q, R, S, X;

B = (0,0);
C = (8,0);
A = intersectionpoint(arc(B,7,0,180),arc(C,9,0,180));
P = interp(A,B,(12 - 3*sqrt(2))/2/7);
Q = interp(A,C,(12 + 3*sqrt(2))/2/9);
R = interp(C,A,6/9);
S = interp(C,B,6/8);
X = extension(P,Q,R,S);

draw(A--B--C--cycle);
draw(interp(P,Q,-0.2)--interp(P,Q,1.2),red);
draw(interp(R,S,-0.2)--interp(R,S,1.2),blue);

label("$\theta$", X + (0.7,0.4));
label("$A$", A, N);
label("$B$", B, SW);
label("$C$", C, SE);
label("$P$", P, SW);
label("$Q$", Q, NE);
label("$R$", R, E);
label("$S$", S, SE);
[/asy]

Let $p = AP$ and $q = AQ.$  Since line $PQ$ bisects the perimeter of the triangle,
\[p + q = \frac{7 + 8 + 9}{2} = 12.\]The area of triangle $APQ$ is $\frac{1}{2} pq \sin A,$ and the area of triangle $ABC$ is $\frac{1}{2} \cdot 7 \cdot 9 \cdot \sin A = \frac{63}{2} \sin A.$  Since line $PQ$ bisects the area of the triangle,
\[\frac{1}{2} pq \sin A = \frac{1}{2} \cdot \frac{63}{2} \sin A,\]so $pq = \frac{63}{2}.$  Then by Vieta's formulas, $p$ and $q$ are the roots of the quadratic
\[t^2 - 12t + \frac{63}{2} = 0.\]By the quadratic formula,
\[t = \frac{12 \pm 3 \sqrt{2}}{2}.\]Since $\frac{12 + 3 \sqrt{2}}{2} > 8$ and $p = AP < AB = 7,$ we must have $p = \frac{12 - 3 \sqrt{2}}{2}$ and $q = \frac{12 + 3 \sqrt{2}}{2}.$

Similarly, if we let $r = CR$ and $s = CS,$ then $rs = 36$ and $r + s = 12,$ so $r = s = 6.$  (By going through the calculations, we can also confirm that there is no bisecting line that intersects $\overline{AB}$ and $\overline{BC}.$)

Let $X$ be the intersection of lines $PQ$ and $RS.$  Let $Y$ be the foot of the altitude from $P$ to $\overline{AC}.$

[asy]
unitsize(0.6 cm);

pair A, B, C, P, Q, R, S, X, Y;

B = (0,0);
C = (8,0);
A = intersectionpoint(arc(B,7,0,180),arc(C,9,0,180));
P = interp(A,B,(12 - 3*sqrt(2))/2/7);
Q = interp(A,C,(12 + 3*sqrt(2))/2/9);
R = interp(C,A,6/9);
S = interp(C,B,6/8);
X = extension(P,Q,R,S);
Y = (P + reflect(A,C)*(P))/2;

draw(A--B--C--cycle);
draw(P--Y);
draw(P--Q);

label("$A$", A, N);
label("$B$", B, SW);
label("$C$", C, SE);
label("$P$", P, W);
label("$Q$", Q, NE);
label("$Y$", Y, NE);
[/asy]

By the Law of Cosines on triangle $ABC,$
\[\cos A = \frac{7^2 + 9^2 - 8^2}{2 \cdot 7 \cdot 9} = \frac{11}{21}.\]Then
\[\sin A = \sqrt{1 - \cos^2 A} = \frac{8 \sqrt{5}}{21},\]so
\begin{align*}
\tan \angle AQP &= \frac{PY}{QY} \\
&= \frac{AP \sin A}{AQ - AY} \\
&= \frac{AP \sin A}{AQ - AP \cos A} \\
&= \frac{\frac{12 - 3 \sqrt{2}}{2} \cdot \frac{8 \sqrt{5}}{21}}{\frac{12 + 3 \sqrt{2}}{2} - \frac{12 - 3 \sqrt{2}}{2} \cdot \frac{11}{21}} \\
&= 3 \sqrt{10} - 4 \sqrt{5}.
\end{align*}Again by the Law of Cosines on triangle $ABC,$
\[\cos C = \frac{8^2 + 9^2 - 7^2}{2 \cdot 8 \cdot 9} = \frac{2}{3}.\]Then
\[\sin C = \sqrt{1 - \cos^2 C} = \frac{\sqrt{5}}{3}.\]Since $CR = CS,$
\begin{align*}
\tan \angle CRS &= \tan \left( 90^\circ - \frac{C}{2} \right) \\
&= \frac{1}{\tan \frac{C}{2}} \\
&= \frac{\sin \frac{C}{2}}{1 - \cos \frac{C}{2}} \\
&= \frac{\frac{\sqrt{5}}{3}}{1 - \frac{2}{3}} \\
&= \sqrt{5}.
\end{align*}Finally,
\begin{align*}
\tan \theta &= \tan (180^\circ - \tan \angle AQP - \tan \angle CRS) \\
&= -\tan (\angle AQP + \angle CRS) \\
&= -\frac{\tan \angle AQP + \tan \angle CRS}{1 - \tan \angle AQP \tan \angle CRS} \\
&= -\frac{(3 \sqrt{10} - 4 \sqrt{5}) + \sqrt{5}}{1 - (3 \sqrt{10} - 4 \sqrt{5}) \sqrt{5}} \\
&= -\frac{3 \sqrt{10} - 3 \sqrt{5}}{21 - 15 \sqrt{2}} \\
&= \frac{\sqrt{10} - \sqrt{5}}{5 \sqrt{2} - 7} \\
&= \frac{(\sqrt{10} - \sqrt{5})(5 \sqrt{2} + 7)}{(5 \sqrt{2} - 7)(5 \sqrt{2} + 7)} \\
&= \boxed{3 \sqrt{5} + 2 \sqrt{10}}.
\end{align*}